home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
090
/
pctj8404.arc
/
SEARCH3.BAS
< prev
next >
Wrap
BASIC Source File
|
1986-09-14
|
896b
|
29 lines
'
'$$$$$$$$$$$$$$
'Subroutine
'$$$$$$$$$$$$$$
'
' This is the basic binary search subroutine.
' Input is the table in which to look up (ITABLE),
' the number of entries in the table (NTABLE), and
' the number whose index is to be found (JKEY).
' Output is the index (INDX) such that
' TABLE(INDX) = JKEY
'
' BASIC BINARY SEARCH
'
8000 rem Start.
REM CMP cmp = 0
ilow. = 1
ihigh. = ntable
'
8020 rem Loop.
imid. = (ihigh.+ilow.)\2 'Integer division truncates!
REM CMP cmp = cmp + 1
if (itable(imid.) = jkey) then indx = imid. : return
if (itable(imid.) > jkey) then ihigh. = imid. - 1
if (itable(imid.) < jkey) then ilow. = imid. + 1
goto 8020
'
return